<template>
  <div class="user-edit">
    <!-- Modal 对话框 -->
    <Modal
      :title="title"
      v-model="visible"
      width="520"
      :loading="visible"
      :mask-closable="type == '0'"
    >
      <div :style="{ maxHeight: maxHeight }" class="drawer-content">
        <Form
          ref="form"
          :model="form"
          :rules="ruleValidate"
          label-position="top"
        >
          <Row :gutter="32">
            <Col span="12">
              <FormItem label="性质名称：" prop="title">
                <Input v-model="form.title" />
              </FormItem>
            </Col>
          </Row>
          <!-- <Row :gutter="32">
            <Col span="12"> 
              <Button type="primary" :loading="submitLoading" @click="submit">保存</Button>
              <Button @click="visible = false">取消</Button>
            </Col>
          </Row> -->
        </Form>
      </div>
      <div slot="footer">
        <Button type="primary" :loading="submitLoading" size="large" @click="submit">保存</Button>
        <Button size="large" @click="cancel">取消</Button>
      </div>
    </Modal>
  </div>
</template>
<script>
import { companyTypeAdd } from "@/api/index";
export default {
  name: "user",
  components: {
  },
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
    },
    type: {
      type: String,
      default: "0",
    },
  },
  data() {
    return {
      visible: this.value,
      title: "添加",
      passColor: "",
      submitLoading: false,
      maxHeight: 510,
      form: {
      },
      ruleValidate: {
        title: [
          { required: true, message: "请输入性质名称", trigger: "blur" }
        ],
      },
      
    };
  },
  methods: {
    submit() {
      this.$refs.form.validate((valid) => {
        if(valid) {
          companyTypeAdd(this.form).then(res => {
            if (res.success) {
              this.$Message.success("操作成功")
              this.visible = false
              this.$emit("on-submit", true);
            }
          })
        }
      });
    },
    cancel() {
      this.visible = false
    },
    setCurrentValue(value) {
      if (value === this.visible) {
        return;
      }
      this.visible = value;
    },
  },
  watch: {
    value(val) {
      this.setCurrentValue(val);
    },
    visible(value) {
      this.$emit("input", value);
    },
  },
};
</script>

<style lang="less">
@import "@/styles/drawer-common.less";
</style>

